package com.djakapm.markdown.editor.component.listener;

import com.djakapm.markdown.editor.component.EditorComponentPresenter;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class TextChangeKeyListener implements KeyListener{
    private EditorComponentPresenter presenter;

    public TextChangeKeyListener(EditorComponentPresenter presenter){
        this.presenter = presenter;
    }

    public void keyTyped(KeyEvent e) {}

    public void keyPressed(KeyEvent e) {
        //Exclude ctrl+S from treated as common key input.
        if(e.getKeyCode() == 83 && e.isControlDown()){
            return;
        }
        //Exclude ctrl+Enter from treated as common key input.
        if(e.getKeyCode() == 10 && e.isControlDown()){
            return;
        }
        
        this.presenter.setContentModified(true);
        this.presenter.reevaluateActions();
    }

    public void keyReleased(KeyEvent e) {}
}
